#include <iostream>
#include <string>
#include <unordered_map> // 引入unordered_map来存储车型和枚举的映射

using namespace std;

enum class VehicleType {
	Car,
	Bus,
	Truck
};

struct Vehicle {
	string plateNumber;
	VehicleType type;
	double weight;
};

// 使用unordered_map来存储车型和枚举的映射关系
unordered_map<string, VehicleType> vehicleTypeMap = {
	{ "Car", VehicleType::Car },
	{ "Bus", VehicleType::Bus },
	{ "Truck", VehicleType::Truck }
};

// 辅助函数，从字符串获取车型枚举
VehicleType getVehicleType(const string& type) {
	if (vehicleTypeMap.find(type) != vehicleTypeMap.end()) {
		return vehicleTypeMap[type];
	}
	return VehicleType::Car; // 如果没有找到，默认返回Car
}

double calculateFee(const Vehicle& vehicle, double mileage) {
	double fee = 0;
	switch (vehicle.type) {
	case VehicleType::Car:
		fee = 0.5 * vehicle.weight * mileage;
		break;
	case VehicleType::Bus:
		fee = 1.5 * vehicle.weight * mileage;
		break;
	case VehicleType::Truck:
		fee = 2.0 * vehicle.weight * mileage;
		break;
	}
	return fee;
}

int main() {
	Vehicle vehicle;
	cout << "请输入车牌：";
	cin >> vehicle.plateNumber;

	bool isValidType = false;
	string type;
	do {
		cout << "请输入车型 (Car/Bus/Truck): ";
		cin >> type;
		vehicle.type = getVehicleType(type);

		// 检查是否输入了有效的车型
		if (vehicleTypeMap.find(type) != vehicleTypeMap.end()) {
			isValidType = true;
		}
		else {
			cout << "输入的车型无效，请重新输入！" << endl;
		}
	} while (!isValidType);

	bool isValidWeight = false;
	do {
		cout << "请输入车重 (kg, 必须大于0): ";
		if (!(cin >> vehicle.weight)) {
			// 清除错误状态
			cin.clear();
			// 忽略无效输入，直到遇到有效的输入字符（如数字或换行符）
			cin.ignore(numeric_limits<streamsize>::max(), '\n');
			cout << "输入的车重无效，请重新输入！" << endl;
		}
		else if (vehicle.weight <= 0) {
			cout << "输入的车重无效（必须大于0），请重新输入！" << endl;
		}
		else {
			isValidWeight = true;
		}
	} while (!isValidWeight);

	double mileage;
	cout << "请输入里程 (km): ";
	cin >> mileage;

	double fee = calculateFee(vehicle, mileage);
	cout << "费用为：" << fee << "元" << endl;

	return 0;
}